<?php
namespace app\tools\logic;
use think\facade\Db;

class OrderSmsLogic{
	static function getList(){
		$member_id 	=	input('member_id', 0);
		$page_size = input('page_size', 10);
		$status = input('status', '');
		
		$start_time = input('start_time', '');
		$end_time = input('end_time', '');
		$start_time && $start_time .= " 00:00:00";
		$end_time && $end_time .= "23:59:59";

		$user_name = input('user_name', '');
		$phone = input('phone', '');
		$order_sn = input('order_sn', '');

		$fields = "or.id, or.order_sn, or.member_id, 
				   round(or.pay_amount,2) as pay_amount,
				   or.phone,or.sms_code,or.sms_content,
				   or.add_time as create_time,or.pay_time,or.status,
				   m.user_name,cc.country_zh,cs.server_zh";

		$obj = Db::name('order_sms')
				->field($fields)
				->alias('or')
				->join('member m','m.id=or.member_id')
				->join('channel_country cc','cc.id=or.country_id')
				->join('channel_server cs','cs.id=or.server_id');
		if($user_name){
			$obj->where('m.user_name','like','%'.$user_name.'%');
		}
		if($phone){
			$obj->where('or.phone','like','%'.$phone.'%');
		}
		if($order_sn){
			$obj->where('or.order_sn','like','%'.$order_sn.'%');
		}
		//时间
		if($start_time){
			$obj->where('or.add_time','>=', $start_time);
		}
		if($end_time){
			$obj->where('or.add_time','<=', $end_time);
		}
		//查询指定用户
		if($member_id){
			$obj->where('or.member_id', $member_id);
		}
		//根据订单状态查询
		if($status!==''){
			// echo $status;
			$obj->where('or.status', $status);
		}

		$list = $obj->order('or.id desc')
				->paginate($page_size);
		return $list;
	}

}